<%--
  Created by IntelliJ IDEA.
  User: acer
  Date: 2018/12/18
  Time: 11:54
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>添加菜品信息</title>
    <script src="/static/js/jquery-3.3.1.js"></script>
    <link rel="stylesheet" href="/static/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/layuiadmin/style/admin.css" media="all">
    <script src="/static/layuiadmin/layui/layui.js" type="text/javascript"></script>
</head>
<body>
<style type="text/css">
    .layui-form-item{
        margin-left: 30px;
        margin-top: 50px;
        width:600px;
    }
</style>


<form id="myform" action="/insertCategory" method="post" class="layui-form">
    <div class="layui-form-item">
        <label class="layui-form-label">分类名称</label>
        <div class="layui-input-block">
            <input type="text" id="caname" name="caname" lay-verify="caname" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>

<script src="../layuiadmin/layui/layui.js" charset="utf-8"></script>

<script>
    layui.use(['form', 'layedit', 'laydate'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate;

        //自定义验证规则
        form.verify({
            caname: function(value){
                if(value.length < 1){
                    return '分类名称不能为空';
                }
            }
        });

        //创建一个编辑器
        layedit.build('LAY_demo_editor');

        //监听提交
        form.on('submit(demo1)', function(data){

            $.ajax({
                url:"insertCategory",    //请求的url地址
                dataType:"json",   //返回格式为json
                contentType:"application/json",
                async:true,//请求是否异步，默认为异步，这也是ajax重要特性
                data:$('#myform').serialize(),  //参数值
                type:"GET",   //请求方式
                success:function(data){
                    //请求成功时处理
                    layer.alert(data.msg, function(index) {
                        //关闭窗口
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                    })
                }
            });
            return false;
        });
    });
</script>
</body>
</html>